<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Componi il tuo volantino</title>
<link rel="stylesheet" type="text/css" href="resources/css/style.css" />
<style type="text/css">
.image {
	margin: 0px;
	background-image: url('resources/images/esempio.jpg');
	background-repeat: no-repeat;
	color: #000000;
	background-color: red;
	font-size: 140%;
	font-weight: normal;
	width: 400px;
	height: 200px;
}
</style>
<script type="text/javascript" src="resources/js/jquery-1.7.1.js"></script>
<script type="text/javascript">
	function update() {
		var company = document.getElementById("company").value;
		var name = document.getElementById("name").value;
		var phone = document.getElementById("phone").value;
		var email = document.getElementById("email").value;
		var chiSiamo = document.getElementById("chiSiamo").value;
		$("#result").html("<h3 style='margin-left: 150px; margin-top: 5px;'>" + company + "</h3>" +
						"<h4 style='margin-left: 5px; margin-top: 20px;'>" + name + "</h4><h7>" + phone + " " + email + "</h7>" +
						"<h6 style='margin-center: 5px; margin-top: 20px;'>" + chiSiamo + "</h6>");
	}
	function stampa() {
		var _company = document.getElementById("company").value;
		var _name = document.getElementById("name").value;
		var _phone = document.getElementById("phone").value;
		var _email = document.getElementById("email").value;
		$.ajax({
			url : 'printBiglietto.htm',
			type : "POST",
			data : ({
				fileName: "volantino" + _company + ".pdf",
				width: 400,
				height: 200,
				background: "http://localhost:8080/Stampa-online/resources/images/esempio.jpg",
				company: _company,
				posCompanyX: 150,
				posCompanyY: 5,
				name: _name,
				posNameX: 5,
				posNameY: 20,
				phone: _phone,
				posPhoneX: 100,
				posPhoneY: 50,
				email: _email,
				posEmailX: 100,
				posEmailY: 70
			}),
			success : function(res) {
				if (res == "yes") {
					alert("OK");
				}
				else {
					alert(":(");
				}
			}
		});
	}
	function visualizzaImg() {
		$.ajax({
			url: "listTemplates.htm",
			type: "POST",
			success : function(res) {
				// Devo scorrere tutti gli elementi della lista
				// che la funzione listTemplates restituisce.
				
				$('#visualizzaImg').html("");
			}
		});
	}
</script>
</head>
<body>
	<div class="box">
		<div id="form">
			<form action="">
				<table>
					<tr>
						<td>Azienda</td>
						<td><input id="company" type="text" onkeyup="update()"></td>
					</tr>
					<tr>
						<td>Nome e Cognome</td>
						<td><input id="name" type="text" onkeyup="update()"></td>
					</tr>
					<tr>
						<td>Telefono</td>
						<td><input id="phone" type="text" onkeyup="update()"></td>
					</tr>
					<tr>
						<td>Email</td>
						<td><input id="email" type="text" onkeyup="update()"></td>
					</tr>
					<tr>
						<td>Chi siamo</td>
						<td><input id="chiSiamo" type="text" onkeyup="update()"></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="result" class="image"></div>
		<input id="stampa" type="button" value="Stampa" onclick="stampa()">
	</div>
	<div class="box"></div>
	<br class="clearfix" />
	<div id="sidebar">
		<div class="box">
			<!-- Visualizza template caricati -->
			<div id="visualizzaImg" class="image"></div>
		</div>
	</div>
	<br class="clearfix" />
</body>
</html>